Add a deferrable update class for callback/closure udpates
authorbsitu <bsitu@wikimedia.org>
Tue, 3 Sep 2013 20:43:40 +0000 (13:43 -0700)
committerbsitu <bsitu@wikimedia.org>
Wed, 4 Sep 2013 06:15:36 +0000 (23:15 -0700)
Change-Id: Ifdf2a0937df50eb2f04d514b5cc2ef39a54ebe8f

RELEASE-NOTES-1.22
includes/AutoLoader.php
includes/CallableUpdate.php [new file with mode: 0644]
includes/DeferredUpdates.php

index b88e323..24aaceb 100644 (file)
@@ -208,6 +208,7 @@ production.
   and Special:AllMyUploads respectively.
 * IPv6 addresses in X-Forwarded-For headers are now normalised before checking
   against allowed proxy lists.
+* Add deferrable update support for callback/closure
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
index 82d204b..677bed3 100644 (file)
@@ -68,6 +68,7 @@ $wgAutoloadLocalClasses = array(
        'CurlHttpRequest' => 'includes/HttpFunctions.php',
        'DeferrableUpdate' => 'includes/DeferredUpdates.php',
        'DeferredUpdates' => 'includes/DeferredUpdates.php',
+       'MWCallableUpdate' => 'includes/CallableUpdate.php',
        'DeprecatedGlobal' => 'includes/DeprecatedGlobal.php',
        'DerivativeRequest' => 'includes/WebRequest.php',
        'DiffHistoryBlob' => 'includes/HistoryBlob.php',
diff --git a/includes/CallableUpdate.php b/includes/CallableUpdate.php
new file mode 100644 (file)
index 0000000..6eb5541
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * Deferrable Update for closure/callback
+ */
+class MWCallableUpdate implements DeferrableUpdate {
+
+       /**
+        * @var closure/callabck
+        */
+       private $callback;
+
+       /**
+        * @param callable $callback
+        */
+       public function __construct( $callback ) {
+               if ( !is_callable( $callback ) ) {
+                       throw new MWException( 'Not a valid callback/closure!' );
+               }
+               $this->callback = $callback;
+       }
+
+       /**
+        * Run the update
+        */
+       public function doUpdate() {
+               call_user_func( $this->callback );
+       }
+
+}
index 89c4df6..a321414 100644 (file)
@@ -63,6 +63,16 @@ class DeferredUpdates {
                self::addUpdate( new HTMLCacheUpdate( $title, $table ) );
        }
 
+       /**
+        * Add a callable update.  In a lot of cases, we just need a callback/closure,
+        * defining a new DeferrableUpdate object is not necessary
+        * @see MWCallableUpdate::__construct()
+        * @param callable $callable
+        */
+       public static function addCallableUpdate( $callable ) {
+               self::addUpdate( new MWCallableUpdate( $callable ) );
+       }
+
        /**
         * Do any deferred updates and clear the list
         *